<template>
  <el-form :model="props.comData" label-width="120px">
    <el-form-item label="角色名称">
      <el-input v-model="props.comData.name" />
    </el-form-item>

    <el-form-item label="角色描述">
      <el-input type="textarea" v-model="props.comData.description" />
    </el-form-item>

    <el-form-item label="状态">
      <el-switch :active-value="1" :inactive-value="0" v-model="props.comData.status" />
    </el-form-item>

    <el-form-item>
      <el-button type="primary" @click="onSubmit">保存</el-button>
      <el-button @click="handleClose">取消</el-button>
    </el-form-item>
  </el-form>
</template>

<script lang="ts" setup>
import { updateById } from "@/api/role/index";
import { reactive, ref, defineProps, computed } from "vue";
import { WholeResult } from "../../../store/module/types/comm/pageType";
import { ElMessage } from "element-plus";

const props = defineProps(["comData"]);
const emits = defineEmits(["handleCloseDailog"]);

/**
 * 表单数据
 */
const defaultForm = {
  name: "",
  description: "",
  status: true,
};

/**
 * 响应式表单数据
 */
let roleForm = reactive(defaultForm);

const handleClose = () => {
  emits("handleCloseDailog");
};

const onSubmit = async () => {
  const result: WholeResult = await updateById(props.comData);
  ElMessage({
    type: result.code == 200 ? "success" : "error",
    message: result.mess,
    center:true,
  });
  handleClose();
};
</script>
